{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "4fd7500e",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "from dotenv import load_dotenv\n",
    "from langchain_openai import ChatOpenAI\n",
    "\n",
    "load_dotenv()\n",
    "\n",
    "# Configure an LLM\n",
    "llm = ChatOpenAI(\n",
    "    model=\"qwen3-32b\",\n",
    "    temperature=0.5,\n",
    "    base_url=\"https://dashscope.aliyuncs.com/compatible-mode/v1\",\n",
    "    api_key=os.environ.get(\"AI_DASHSCOPE_API_KEY\"),\n",
    "    streaming=True,\n",
    "    extra_body={\"enable_thinking\": False}\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "b27a3078",
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import Annotated, TypedDict\n",
    "from langgraph.graph import StateGraph, START\n",
    "from langgraph.graph.message import add_messages\n",
    "\n",
    "\n",
    "class State(TypedDict):\n",
    "    # Messages have the type \"list\". The `add_messages` function\n",
    "    # in the annotation defines how this state key should be updated\n",
    "    # (in this case, it appends messages to the list, rather than overwriting them)\n",
    "    messages: Annotated[list, add_messages]\n",
    "\n",
    "graph_builder = StateGraph(State)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "7cf0ebcf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<langgraph.graph.state.StateGraph at 0x1ca56f758b0>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def chatbot(state: State):\n",
    "    return {\"messages\": [llm.invoke(state[\"messages\"])]}\n",
    "\n",
    "# The first argument is the unique node name\n",
    "# The second argument is the function or object that will be called whenever\n",
    "# the node is used.\n",
    "graph_builder.add_node(\"chatbot\", chatbot)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "504062fc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<langgraph.graph.state.StateGraph at 0x1ca56f758b0>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "graph_builder.add_edge(START, \"chatbot\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "77b21f4b",
   "metadata": {},
   "outputs": [],
   "source": [
    "graph = graph_builder.compile()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "6124253c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAGoAAACGCAIAAAC6xYg5AAAAAXNSR0IArs4c6QAAEE9JREFUeJztnXtUE9e+gPdMJg8yJDwSAshLCaj4gKMRsCLVcmzVihXQ46PYWs9d56r3Wm9rufZ21UdPH1fbe9ax93pqn561WovV1morYqt4lgqKFVFBCYIQwBggQN7JhDxmMvePcNC2CWQyRIKdby3XCjN7T37zuWdmz56d+UEkSQIGf4FHO4CxDaOPFow+WjD6aMHoowWjjxYIzfqGPqdR67SacMxE4A4y+LtBEASxORBfyEKFSJiYEyamZQDyb4d7lHZFvaVdbgmXcAicRIUIX8ji8GDgohPMwwBmQTYrgZlwq4kAELAY8AlTUWmGQBLP8WNrlPXp1I7qkxoeikRGsydMC42QsP341uBB2+3okGP6XofT4ZqTLw4TU9sdavoul2vbGrCcfNH4qSj1UIMaxU3LpTLtZJkga1Gk77Uo6Pt6772Z8yNSZoT6G+EYoKnW3PiTsWhzvK8VSF8gyA9KWnqUNp8Kj3E6W62fbm/zsbBP+j4oabX3E/SiGksYNc5PX1f4UnL4g/frvffmr5BIErgjcGyMHTpb+2tO6wr/PW7oYsPou1yuFY/jpj7S5ztv3K4xmw141lMRQ5QZ6q5Dp3a0NWC/TXcAgLQsQeNPRrMeH6LMUPqqT2py8kUBCGzMkLNUXH1SM0QBr/p6lHYeijx6/TtKpM4IhSBI2+3wVsCrPkW9JTL6Yd9RLFiwoLOzk2qtI0eO7Nq1KzARgTARu+2Wxdtar/ra5ZYJ0x7qWU+lUhkM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j5uCJz5ZIS5x0S1YjBj7DLOLYjyuZ96H3+edch+H0E6bOY+amM7QYupx8JBHBm5/uTv8vM57zP/Gqtp11r1dv+qBw/mPqtJbVy8LsaHsh6gNcvg4H8rIxIjQkVjY27GrzH1Yja9eeVL/k80oDtJ47uPuiAOPyx27D14M3QZEeDI/xc/252bEZgidPWM/sYFg0QaGe7XI6SHj77L3Nuqy3wycmYe3QSmIzNBDTMRlcc1ZgNJshBhFBoiDFQCFDpYjXZzn5XEnaJoVu4yMdUunkdGcnqkTu28U2dW1GMkgFwugLinR7Jh0jU6v7yBYZhwEoQTx+0EIEmEA1IzQlNnhIZHjdg004BMzsUMhL7P4U5ghDtcxOhMLgUsBCBsGBWyUCESEc3lC0Z+Incw/ihrDBG8M+vHBIw+WjD6aMHoowWjjxaMPlr8PxAaAGhtuBjsAAAAAElFTkSuQmCC",
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from IPython.display import Image, display\n",
    "\n",
    "try:\n",
    "    display(Image(graph.get_graph().draw_mermaid_png()))\n",
    "except Exception:\n",
    "    # This requires some extra dependencies and is optional\n",
    "    pass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "71d3cdfd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "================================\u001b[1m Human Message \u001b[0m=================================\n",
      "\n",
      "你好，我是李明\n",
      "==================================\u001b[1m Ai Message \u001b[0m==================================\n",
      "\n",
      "你好，李明！很高兴认识你。我是Qwen，一个AI助手。有什么我可以帮你的吗？无论是解答问题、提供信息还是其他方面的需求，我都会尽力协助你。\n",
      "================================\u001b[1m Human Message \u001b[0m=================================\n",
      "\n",
      "现在洛杉矶的天气怎么样？\n",
      "==================================\u001b[1m Ai Message \u001b[0m==================================\n",
      "\n",
      "你好！我无法实时获取当前的天气信息，但我可以告诉你如何查看洛杉矶的最新天气情况：\n",
      "\n",
      "1. **使用天气应用**：如“墨迹天气”、“AccuWeather”或“Windy”，这些应用通常提供详细的天气预报。\n",
      "2. **访问天气网站**：例如 [weather.com](https://www.weather.com) 或 [accuweather.com](https://www.accuweather.com)，搜索“Los Angeles”即可。\n",
      "3. **用搜索引擎查询**：在 Google 或百度 搜索 “洛杉矶 天气”，会直接显示当前天气和未来几天的预报。\n",
      "\n",
      "如果你告诉我具体日期，我可以帮你分析洛杉矶在那个时间段的一般天气情况（基于历史数据）。需要吗？\n"
     ]
    }
   ],
   "source": [
    "user_inputs = [\"你好，我是李明\", \"现在洛杉矶的天气怎么样？\"]\n",
    "\n",
    "for user_input in user_inputs:\n",
    "    events = graph.stream({\"messages\": [{\"role\": \"user\", \"content\": user_input}]}, stream_mode=\"values\", )\n",
    "    for event in events:\n",
    "        event[\"messages\"][-1].pretty_print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "ddd26c0c",
   "metadata": {},
   "outputs": [],
   "source": [
    "from langchain_tavily import TavilySearch\n",
    "\n",
    "tool = TavilySearch(max_results=2)\n",
    "tools = [tool]\n",
    "\n",
    "# Modification: tell the LLM which tools it can call\n",
    "llm_with_tool = llm.bind_tools(tools)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "7da2a50b",
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import Annotated, TypedDict\n",
    "\n",
    "from langchain_tavily import TavilySearch\n",
    "\n",
    "from langgraph.graph import StateGraph, START\n",
    "from langgraph.graph.message import add_messages\n",
    "from langgraph.prebuilt import ToolNode, tools_condition\n",
    "\n",
    "class State(TypedDict):\n",
    "    messages: Annotated[list, add_messages]\n",
    "\n",
    "graph_builder = StateGraph(State)\n",
    "\n",
    "tool = TavilySearch(max_results=2)\n",
    "tools = [tool]\n",
    "llm_with_tool = llm.bind_tools(tools)\n",
    "\n",
    "def chatbot(state: State):\n",
    "    return {\"messages\": [llm_with_tool.invoke(state[\"messages\"])]}\n",
    "\n",
    "graph_builder.add_node(\"chatbot\", chatbot)\n",
    "\n",
    "tool_node = ToolNode(tools=[tool])\n",
    "graph_builder.add_node(\"tools\", tool_node)\n",
    "\n",
    "graph_builder.add_conditional_edges(\"chatbot\", tools_condition)\n",
    "\n",
    "# Any time a tool is called, we return to the chatbot to decide the next step\n",
    "graph_builder.add_edge(\"tools\", \"chatbot\")\n",
    "graph_builder.add_edge(START, \"chatbot\")\n",
    "graph = graph_builder.compile()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "42ca440f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAANgAAAD5CAIAAADKsmwpAAAAAXNSR0IArs4c6QAAIABJREFUeJzt3WlcE9feB/CTZLLAAAn7vkVBQFAUFOuKolhFVLwurXhrtVbr0urFpdZe1Gpd+litlbq2VVu1ilYFta17RQuKgkJBFrVsCgEJBLLv87yIF6kGRctkTsj5fvoCMpM5f5qfs5ycOUMjCAIgCNXoVBeAIAAFEYEFCiICBRREBAooiAgUUBARKGBUF/A6VApdQ41aLtHJJVqtltCqzaAHim1Fx1g0a1vM2o7h6s2huhzomFMQZWLN/duyskKpuEFj68C0tmVY22J2DkxgDl2heh2oq1DJJTImm15VIvcPxflhOD/Mhuq6YEEziw5tvY7IOt0grFE5erD4oTaeXa2orugfUcp15YWyR/flNWXK/mMcA3rZUl0R9cwgiHdvNF85Vt8/3rFXtD3VtXQwcYMm60yDSq6L/beblQ2D6nKoBHsQrxx7zLGm94tzoroQEgkFqrTt1W9Od/MKsKa6FspAHcQLB+vc/DlhA7hUF2IKJ7dXD0pwcvJgU10INeANYtqO6q7hNqH9LSKFBie3PwobwOsabolXMJD2I15Lq/cLwS0qhQCAhPleN35rENWpqS6EAjAGsfS2BGPSw6N5VBdCgcTlPr8fewztYYo8MAYx41h972GWmEIAAI1G8wvBs043UF2IqUEXxNyLotABdmwry+3L6D3MvihbrJTpqC7EpOAKIkEQVaXy/mM6c2dNewye4JyX0UR1F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C+aNPhPiYue3tU1hWePAeF5bS1EQKTBovOOtSyKP7sZnWgvg90mad8DoIpVKwWYbP9lnsTryWO/vG95WDS/AZrd5IiQTKZlMwi/kRWdKKIimFtDL9n6eTClRGb15j8XiOLA8qKjrbxzsO7IGpUgydNJLLtHQOSIFRs9wK7tZo9dbxDRRdffqu/WycnnZ5HIoiNR4e5lP2Y1HVFdBurr7Dc7u9ND+3JeuiYJIDXsX1tSPPe//UaXTmvH0fy9W/1dDlxDmsMntmncYBZEy1jbMKYu97v9RJRO1OUrPTOm1+urCWr9ALHK4fTvfgoJIJTsH5gdfdGHqZY/yBQpxJ+lfrC8XlV6tGhjH6xP7Cl+IoKtm6sVOc314T371pJBtw6azWHbOOLS3+b2AtEEhFcrFj6U9B/M8Iyy7AAABWUlEQVQmzevyqm9HQYSCd6B14sc+lUWye3myspvV9u5WaqUeY2EMFmZsJCEU6HS6RqnRaXSA0IsEChdvTkgEHtLP71VnRjRAQYSIbwjuG4IDAOqqlBKRVi7WKuV6lRzSqxkODugMDLdjW9th7v5uTNY/+heDgggjVx+OK4n308HIeBBZHJoemNnsua3hPCadYcb1WyDju1Nbe2Z9pRn3KVQVSx3cIH0eLGKU8SC6eLPNbTrxpxRSrZMn24aHzjrMSZt7RM+unKvH2zXXJ2wuHqzpM6K9/agIJF70vOa715vv50l7DnG0d2UxMFh7Ef5HKdeJherM9MdvvuPq4mOJEx2ZtZc8OLz8riwvo6m2XMlgQn2o5joyxY0avxA8coS9vQs6OzQ/LwliC5UC0t4sA0IPODjs+2zkBdobRAQhFdqLIFBAQUSggIKIQAEFEYECCiICBRREBAr/D1F6E7tD+TbsAAAAAElFTkSuQmCC",
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "try:\n",
    "    display(Image(graph.get_graph().draw_mermaid_png()))\n",
    "except Exception:\n",
    "    # This requires some extra dependencies and is optional\n",
    "    pass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "e28e3ce7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "================================\u001b[1m Human Message \u001b[0m=================================\n",
      "\n",
      "你好，我是李明\n",
      "==================================\u001b[1m Ai Message \u001b[0m==================================\n",
      "\n",
      "你好，李明！有什么我可以帮你的吗？\n",
      "================================\u001b[1m Human Message \u001b[0m=================================\n",
      "\n",
      "现在洛杉矶的天气怎么样？\n",
      "==================================\u001b[1m Ai Message \u001b[0m==================================\n",
      "Tool Calls:\n",
      "  tavily_search (call_16b78906c37e4a02a58c5d)\n",
      " Call ID: call_16b78906c37e4a02a58c5d\n",
      "  Args:\n",
      "    query: 现在洛杉矶的天气怎么样？\n",
      "=================================\u001b[1m Tool Message \u001b[0m=================================\n",
      "Name: tavily_search\n",
      "\n",
      "{\"query\": \"现在洛杉矶的天气怎么样？\", \"follow_up_questions\": null, \"answer\": null, \"images\": [], \"results\": [{\"url\": \"https://www.weather.com.cn/weather/401040101.shtml\", \"title\": \"【洛杉矶天气】洛杉矶天气预报,天气预报一周,天气预报15天查询\", \"content\": \"【洛杉矶天气】洛杉矶天气预报,天气预报一周,天气预报15天查询 首页预报预警雷达云图天气地图专业产品资讯视频节气我的天空 更多  台风路径空间天气图片专题环境旅游碳中和气象科普一带一路产创平台 Image 1 Image 2 国内)本地)国际) 热门城市 北京上海成都杭州南京天津深圳重庆西安广州青岛武汉 热门景点 故宫阳朔漓江龙门石窟野三坡颐和园九寨沟东方明珠凤凰古城秦始皇陵桃花源 选择省市 高球佘山春城湖畔华彬庄园观澜湖依必朗旭宝博鳌玉龙雪山番禺南沙东方明珠 <<返回 全国 河北 下辖区域 Image 3 周边城市 周边景点 本地乡镇 Image 4 热门城市 曼谷东京首尔吉隆坡新加坡巴黎罗马伦敦雅典柏林纽约温哥华墨西哥城哈瓦那圣何塞巴西利亚布宜诺斯艾利斯圣地亚哥利马基多悉尼墨尔本惠灵顿奥克兰苏瓦开罗内罗毕开普敦维多利亚拉巴特 选择洲际 亚洲欧洲北美洲南美洲非洲大洋洲Image 5 美国>洛杉矶（Los Angeles）  今天 周末 7天 8-15天 1日（今天） _16℃_ _<3级_ 2日（明天） 多云转阴 21℃/_15℃_ _<3级_ 3日（后天） 阴转小雨 20℃/_15℃_ _<3级_ 4日（周三） 多云转晴 20℃/_14℃_ _<3级_ 5日（周四） 20℃/_15℃_ 21℃/_15℃_ 21℃/_15℃_ 埃斯佩兰萨站 _/_ _-4/-3°C_ 埃普利机场 _/_ _17/30°C_ 埃默里 _/_ _-24/-24°C_ 埃尔帕索 _/_ _20/30°C_ 阿蒙森斯科特 _/_ _-52/-41°C_ 埃尼威托克 _/_ _28/27°C_ 艾弗罗塔机场 _/_ _10/24°C_ 阿拉莫萨 _/_ _10/20°C_ 阿尼亚克 _/_ _5/10°C_ 艾科 _/_ _12/24°C_ 阿伯丁试验场 _/_ _9/20°C_ 埃斯卡诺巴 _/_ _8/21°C_ Image 6 更多>>高清图集 Image 7: 包罗万“馅”粽享端午好时光 Image 8: 六一儿童节 花花游乐园中的快乐瞬间 Image 9: 三夏时节麦飘香 正是收获好“丰”景 Image 10: 北京街头蔷薇花开 邂逅一场浪漫花事 Image 11: 青海西宁出现日晕景观 光环闪耀天空 Image 12: 江西永新朝霞绚烂 美如油画 Image 14\", \"score\": 0.9857, \"raw_content\": null}, {\"url\": \"https://weather.com/zh-CN/weather/hourbyhour/l/Los+Angeles+CA+United+States?canonicalCityId=7d3c65d8b80674fb48647ddbc936bb8b\", \"title\": \"洛杉矶, CA, 美国每小时天气预报\", \"content\": \"洛杉矶, CA, 美国每小时天气预报 - The Weather Channel | Weather.com *   大风 东南 2 公里/小时  *   大风 东南 1 公里/小时  *   大风 南 4 公里/小时  *   大风 南 4 公里/小时  *   大风 南 5 公里/小时  *   大风 南 5 公里/小时  *   大风 西南偏南 6 公里/小时  *   大风 西南偏南 6 公里/小时  *   大风 东南 2 公里/小时  *   大风 东北 1 公里/小时  *   大风 东南 5 公里/小时  *   大风 东南 3 公里/小时  *   大风 东南 3 公里/小时  *   大风 东南 2 公里/小时  *   大风 东南 2 公里/小时  Image 1: The Weather CompanyImage 2: The Weather ChannelImage 3: Weather UndergroundImage 4: Storm Radar 根据由 The Weather Company 委托进行的 ForecastWatch 全球和区域天气预报准确度概览) 报告，2017 年至 2022 年的数据显示，The Weather Channel 是全球最准确的天气预报服务供应商。 Weather Channel © The Weather Company, LLC 2025\", \"score\": 0.98111, \"raw_content\": null}], \"response_time\": 1.35}\n",
      "==================================\u001b[1m Ai Message \u001b[0m==================================\n",
      "\n",
      "目前洛杉矶的天气如下：\n",
      "\n",
      "- **今天**：16°C，风速小于3级。\n",
      "- **明天**：多云转阴，气温在15°C至21°C之间，风速小于3级。\n",
      "- **后天**：阴转小雨，气温在15°C至20°C之间，风速小于3级。\n",
      "\n",
      "如需更详细的每小时天气预报或其他信息，请告诉我！\n",
      "================================\u001b[1m Human Message \u001b[0m=================================\n",
      "\n",
      "我问了什么问题？\n",
      "==================================\u001b[1m Ai Message \u001b[0m==================================\n",
      "\n",
      "你问的是“我问了什么问题？”。\n"
     ]
    }
   ],
   "source": [
    "user_inputs = [\"你好，我是李明\", \"现在洛杉矶的天气怎么样？\", \"我问了什么问题？\"]\n",
    "\n",
    "for user_input in user_inputs:\n",
    "    events = graph.stream({\"messages\": [{\"role\": \"user\", \"content\": user_input}]}, stream_mode=\"values\", )\n",
    "    for event in events:\n",
    "        event[\"messages\"][-1].pretty_print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "328daaea",
   "metadata": {},
   "outputs": [],
   "source": [
    "from langgraph.checkpoint.memory import MemorySaver\n",
    "\n",
    "memory = MemorySaver()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "1d331f6c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAANgAAAD5CAIAAADKsmwpAAAAAXNSR0IArs4c6QAAIABJREFUeJzt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+b2AtEEhFcrFj6U9B/M8Iyy7AAABWUlEQVQmzevyqm9HQYSCd6B14sc+lUWye3myspvV9u5WaqUeY2EMFmZsJCEU6HS6RqnRaXSA0IsEChdvTkgEHtLP71VnRjRAQYSIbwjuG4IDAOqqlBKRVi7WKuV6lRzSqxkODugMDLdjW9th7v5uTNY/+heDgggjVx+OK4n308HIeBBZHJoemNnsua3hPCadYcb1WyDju1Nbe2Z9pRn3KVQVSx3cIH0eLGKU8SC6eLPNbTrxpxRSrZMn24aHzjrMSZt7RM+unKvH2zXXJ2wuHqzpM6K9/agIJF70vOa715vv50l7DnG0d2UxMFh7Ef5HKdeJherM9MdvvuPq4mOJEx2ZtZc8OLz8riwvo6m2XMlgQn2o5joyxY0avxA8coS9vQs6OzQ/LwliC5UC0t4sA0IPODjs+2zkBdobRAQhFdqLIFBAQUSggIKIQAEFEYECCiICBRREBAr/D1F6E7tD+TbsAAAAAElFTkSuQmCC",
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "graph = graph_builder.compile(checkpointer=memory)\n",
    "\n",
    "try:\n",
    "    display(Image(graph.get_graph().draw_mermaid_png()))\n",
    "except Exception:\n",
    "    # This requires some extra dependencies and is optional\n",
    "    pass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "d90b6c48",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "================================\u001b[1m Human Message \u001b[0m=================================\n",
      "\n",
      "你好，我是李明\n",
      "==================================\u001b[1m Ai Message \u001b[0m==================================\n",
      "\n",
      "你好，李明！有什么我可以帮你的吗？\n",
      "================================\u001b[1m Human Message \u001b[0m=================================\n",
      "\n",
      "现在洛杉矶的天气怎么样？\n",
      "==================================\u001b[1m Ai Message \u001b[0m==================================\n",
      "Tool Calls:\n",
      "  tavily_search (call_7de25852fc9e449cb7e668)\n",
      " Call ID: call_7de25852fc9e449cb7e668\n",
      "  Args:\n",
      "    query: 现在洛杉矶的天气\n",
      "=================================\u001b[1m Tool Message \u001b[0m=================================\n",
      "Name: tavily_search\n",
      "\n",
      "{\"query\": \"现在洛杉矶的天气\", \"follow_up_questions\": null, \"answer\": null, \"images\": [], \"results\": [{\"url\": \"https://www.weather.com.cn/weather/401040101.shtml\", \"title\": \"【洛杉矶天气】洛杉矶天气预报,天气预报一周,天气预报15天查询\", \"content\": \"【洛杉矶天气】洛杉矶天气预报,天气预报一周,天气预报15天查询 首页预报预警雷达云图天气地图专业产品资讯视频节气我的天空 更多  台风路径空间天气图片专题环境旅游碳中和气象科普一带一路产创平台 Image 1 Image 2 国内)本地)国际) 热门城市 北京上海成都杭州南京天津深圳重庆西安广州青岛武汉 热门景点 故宫阳朔漓江龙门石窟野三坡颐和园九寨沟东方明珠凤凰古城秦始皇陵桃花源 选择省市 高球佘山春城湖畔华彬庄园观澜湖依必朗旭宝博鳌玉龙雪山番禺南沙东方明珠 <<返回 全国 河北 下辖区域 Image 3 周边城市 周边景点 本地乡镇 Image 4 热门城市 曼谷东京首尔吉隆坡新加坡巴黎罗马伦敦雅典柏林纽约温哥华墨西哥城哈瓦那圣何塞巴西利亚布宜诺斯艾利斯圣地亚哥利马基多悉尼墨尔本惠灵顿奥克兰苏瓦开罗内罗毕开普敦维多利亚拉巴特 选择洲际 亚洲欧洲北美洲南美洲非洲大洋洲Image 5 美国>洛杉矶（Los Angeles）  今天 周末 7天 8-15天 1日（今天） _16℃_ _<3级_ 2日（明天） 多云转阴 21℃/_15℃_ _<3级_ 3日（后天） 阴转小雨 20℃/_15℃_ _<3级_ 4日（周三） 多云转晴 20℃/_14℃_ _<3级_ 5日（周四） 20℃/_15℃_ 21℃/_15℃_ 21℃/_15℃_ 埃斯佩兰萨站 _/_ _-4/-3°C_ 埃普利机场 _/_ _17/30°C_ 埃默里 _/_ _-24/-24°C_ 埃尔帕索 _/_ _20/30°C_ 阿蒙森斯科特 _/_ _-52/-41°C_ 埃尼威托克 _/_ _28/27°C_ 艾弗罗塔机场 _/_ _10/24°C_ 阿拉莫萨 _/_ _10/20°C_ 阿尼亚克 _/_ _5/10°C_ 艾科 _/_ _12/24°C_ 阿伯丁试验场 _/_ _9/20°C_ 埃斯卡诺巴 _/_ _8/21°C_ Image 6 更多>>高清图集 Image 7: 包罗万“馅”粽享端午好时光 Image 8: 六一儿童节 花花游乐园中的快乐瞬间 Image 9: 三夏时节麦飘香 正是收获好“丰”景 Image 10: 北京街头蔷薇花开 邂逅一场浪漫花事 Image 11: 青海西宁出现日晕景观 光环闪耀天空 Image 12: 江西永新朝霞绚烂 美如油画 Image 14\", \"score\": 0.98541, \"raw_content\": null}, {\"url\": \"https://weather.com/zh-CN/weather/hourbyhour/l/Los+Angeles+CA+United+States?canonicalCityId=7d3c65d8b80674fb48647ddbc936bb8b\", \"title\": \"洛杉矶, CA, 美国每小时天气预报 - The Weather Channel\", \"content\": \"洛杉矶, CA, 美国每小时天气预报 - The Weather Channel | Weather.com *   大风 东南 2 公里/小时  *   大风 东南 1 公里/小时  *   大风 南 4 公里/小时  *   大风 南 4 公里/小时  *   大风 南 5 公里/小时  *   大风 南 5 公里/小时  *   大风 西南偏南 6 公里/小时  *   大风 西南偏南 6 公里/小时  *   大风 东南 2 公里/小时  *   大风 东北 1 公里/小时  *   大风 东南 5 公里/小时  *   大风 东南 3 公里/小时  *   大风 东南 3 公里/小时  *   大风 东南 2 公里/小时  *   大风 东南 2 公里/小时  Image 1: The Weather CompanyImage 2: The Weather ChannelImage 3: Weather UndergroundImage 4: Storm Radar 根据由 The Weather Company 委托进行的 ForecastWatch 全球和区域天气预报准确度概览) 报告，2017 年至 2022 年的数据显示，The Weather Channel 是全球最准确的天气预报服务供应商。 Weather Channel © The Weather Company, LLC 2025\", \"score\": 0.98467, \"raw_content\": null}], \"response_time\": 0.9}\n",
      "==================================\u001b[1m Ai Message \u001b[0m==================================\n",
      "\n",
      "根据最新的天气预报，洛杉矶目前的天气情况如下：\n",
      "\n",
      "- **今天**：16°C，风速小于3级。\n",
      "- **明天**：多云转阴，气温在15°C到21°C之间，风速小于3级。\n",
      "- **后天**：阴转小雨，气温在15°C到20°C之间，风速小于3级。\n",
      "\n",
      "总体来看，未来几天的天气较为凉爽，建议根据具体活动安排携带适当的衣物。如果需要更详细的每小时天气信息，可以参考其他来源。\n",
      "================================\u001b[1m Human Message \u001b[0m=================================\n",
      "\n",
      "我问了什么问题？\n",
      "==================================\u001b[1m Ai Message \u001b[0m==================================\n",
      "\n",
      "你问的是“现在洛杉矶的天气怎么样？”。\n"
     ]
    }
   ],
   "source": [
    "config = {\"configurable\": {\"thread_id\": \"1\"}}\n",
    "\n",
    "user_inputs = [\"你好，我是李明\", \"现在洛杉矶的天气怎么样？\", \"我问了什么问题？\"]\n",
    "\n",
    "for user_input in user_inputs:\n",
    "    events = graph.stream({\"messages\": [{\"role\": \"user\", \"content\": user_input}]}, config, stream_mode=\"values\", )\n",
    "    for event in events:\n",
    "        event[\"messages\"][-1].pretty_print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "296fd41d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "================================\u001b[1m Human Message \u001b[0m=================================\n",
      "\n",
      "我问了什么问题？\n",
      "==================================\u001b[1m Ai Message \u001b[0m==================================\n",
      "\n",
      "你问的是“我问了什么问题？”。\n"
     ]
    }
   ],
   "source": [
    "config = {\"configurable\": {\"thread_id\": \"2\"}}\n",
    "\n",
    "user_input = \"我问了什么问题？\"\n",
    "\n",
    "events = graph.stream({\"messages\": [{\"role\": \"user\", \"content\": user_input}]}, config, stream_mode=\"values\",)\n",
    "for event in events:\n",
    "    event[\"messages\"][-1].pretty_print()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
